<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<%@ page import="com.scalar.chiptrack.utils.ConfigManager"%>
<%@ page import="com.scalar.chiptrack.commons.SessionKeys"%>
<%@ page import="com.scalar.chiptrack.users.Functionality"%>
<%@ page import="com.scalar.chiptrack.users.User"%>
<%@ page import="com.scalar.chiptrack.commons.Constants" %>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>
<% User user1 = (User) session.getAttribute (SessionKeys.USER_KEY); %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>
<!--This additions have been made to give the functionality of success.jsp to this page aswell-->
<%
    String action=request.getParameter("action");
    if( action == null )
    {
        action = "";
    }
    else
    {
        action = action.trim();
    }
%>

<SCRIPT language="JavaScript">
    function searchCustomer(theForm)
    {
        theForm.action.value = "SearchCustomer";
        theForm.submit();
    }
    function submitPage()
    {
        document.selectCustomerForm.action.value="SearchCustomer";
        document.selectCustomerForm.submit();
    }
    function showErrorReportPage()
    {
        newWindow = window.open ('<%=chipTracContext%>/reportProblem.do','reportProblem','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=750,height=400,resizable=no');
        newWindow.focus();
    }
    function openCustomer()
    {
        newWindow = window.open('customers.do?action=PrintCustomer&customerId=<%=(String)request.getAttribute("customerId")%>','optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=600,height=600,left=100,top=50,resizable=yes');
        newWindow.focus();
    }

    function openSalesOrder()
    {
        var isSample = document.selectCustomerForm.isSample.value;
        window.open('order.do?action=printOrder&revisedDate=false&salesOrderId=<%=(String)request.getAttribute("salesOrderId")%>&isSample='+isSample,'optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=600,height=600,left=100,top=50,resizable=yes');
    }

    function openQuotation()
    {
        newWindow = window.open('quotationView.do?action=printQuotation&salesOrderId=<%=(String)request.getAttribute("salesOrderId")%>&salesOrderNo=<%=(String)request.getParameter("salesOrderNo")%>','optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=600,height=600,left=100,top=50,resizable=yes');
  	    newWindow.focus();
    }

</SCRIPT>
</HEAD>
<BODY bgColor="#ffffff" leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">
<%
    String userTypeChiptrac = Constants.USER_TYPE_CHIPTRAC + "";
%>
<logic:equal value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
    <%@ include file="/jsp/includes/header.jsp" %>
</logic:equal>
<logic:notEqual value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
    <%@ include file="/jsp/includes/extHeader.jsp" %>
</logic:notEqual>

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
    <TBODY>
    <TR>
        <td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
        <!-- Side Navigation start -->
        <%
            String heading = "";
            int isSample = 1;
            if( ( request.getParameter( "isSample" ) != null ) && ( request.getParameter( "isSample" ).equals( "0" ) ) )
            {
                 heading = "Sample Order";
                 isSample = 0;
        %>
        <logic:equal value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
            <%@ include file="/jsp/sales/sample_order_menu.jsp" %>
        </logic:equal>
        <logic:notEqual value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
            <%@ include file="/jsp/sales/ext_sample_order_menu.jsp" %>
        </logic:notEqual>
        <%
            }
            else
            {
                heading = "Sales Order";
                isSample = 1;
        %>
        <logic:equal value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
            <%@ include file="/jsp/sales/sales_order_menu.jsp" %>
        </logic:equal>
        <logic:notEqual value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
            <%@ include file="/jsp/sales/ext_sales_order_menu.jsp" %>
        </logic:notEqual>
        <%
            }
        %>
        <!-- end of the side navigations -->
        </TD>
        <TD bgcolor="#ffffff"><IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
        <TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
        <TD valign="top" width="100%">
            <IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
            <BR>
            <html:form name="selectCustomerForm" method="post" action="/selectCustomer" type="com.scalar.chiptrack.sales.forms.SelectCustomerForm" onsubmit="javascript:searchCustomer(document.selectCustomerForm);">
            <center><span class="NArialW">Select the Customer for the <%=heading%> </span></center>
            <img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20>
            <div align=right>
            <table border="0" width="90%">
                <tr>
                    <td>
                        <chiptrack:info styleClass="NArialL" />
                        <chiptrack:errors styleClass="NArialL" />
                        <chiptrack:messages type="info" styleClass="NArialL" />
                    </td>
                </tr>
            </table>
            </div>
            <br>
            <table border="0" width="90%" align=right>
                <tr>
                    <td>
                        <table border="0" width="100%" align=right>
                            <tr>
                                <td width="15%"><font class="NArialL">Customer</font></td>
                                <td width="20%"><font class="NArialL">
                                    <html:text name="selectCustomerForm" property="customerName" styleClass="txfield" size="23" />
                                </td>
                                <td width="5%" class="NArialL">(or)&nbsp;</td>
                                <td width="15%" class="NArialL">Select Customer</td>
                                <td width="20%" class="NArialL">
                                    <html:select name="selectCustomerForm" property="selectedCustomer" styleClass="txfield" >
                                        <html:options collection="customers" property="value" labelProperty="label"/>
                                    </html:select>
                                </td>
                            </tr>
                            <tr><td colspan='5'><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
                            <tr>
                                <td colspan=5 align=center>
                                    <% if ( isSample == 1 ) { %>
                                        <chiptrack:restrictedLink functionality='<%=Functionality.SALES_NEW_SALES_ORDER%>' action='<%=User.USER_ACTION_VIEW%>' styleClass="leftsection" href="javascript:searchCustomer(document.selectCustomerForm);"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/search.gif"  onmouseover="window.status='Click to search for customers';return true" onmouseout="window.status='';return true" title="Click here to Search for Customers"></chiptrack:restrictedLink>
                                    <% } else { %>
                                        <chiptrack:restrictedLink functionality='<%=Functionality.SAMPLE_NEW_SAMPLE_ORDER%>' action='<%=User.USER_ACTION_VIEW%>' styleClass="leftsection" href="javascript:searchCustomer(document.selectCustomerForm);"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/search.gif"  onmouseover="window.status='Click to search for customers';return true" onmouseout="window.status='';return true" title="Click here to Search for Customers"></chiptrack:restrictedLink>
                                    <% } %>
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <a href="javascript:document.selectCustomerForm.reset();"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif"  onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true" title="Click here to Reset"  width="53" height="17"></a>
                                </td>
                            </tr>
                            <tr><td colspan=5><img height=10 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif"></td></tr><tr><td>
                            <% if ( isSample == 1 && user1.isActionAllowed ( Functionality.SALES_NEW_SALES_ORDER,User.USER_ACTION_VIEW ) ) { %>
                            <tr>
                                <td class="NArialL" colspan=5>
                                    To add a new <%=heading%>, please
                                    <chiptrack:restrictedLink functionality='<%=Functionality.SALES_NEW_SALES_ORDER%>' action='<%=User.USER_ACTION_VIEW%>' styleClass="leftsection" href="javascript:searchCustomer(document.selectCustomerForm);" onmouseover="window.status='Click to Add new Sales Order';return true" onmouseout="window.status='';return true">click here</chiptrack:restrictedLink>
                                </td>
                            </tr>
                            <% } %>
                            <% if ( isSample == 0 && user1.isActionAllowed ( Functionality.SAMPLE_NEW_SAMPLE_ORDER,User.USER_ACTION_VIEW ) ) { %>
                            <tr>
                                <td class="NArialL" colspan=5>
                                    To add a new <%=heading%>, please
                                    <chiptrack:restrictedLink functionality='<%=Functionality.SAMPLE_NEW_SAMPLE_ORDER%>' action='<%=User.USER_ACTION_VIEW%>' styleClass="leftsection" href="javascript:searchCustomer(document.selectCustomerForm);" onmouseover="window.status='Click to Add new Sales Order';return true" onmouseout="window.status='';return true">click here</chiptrack:restrictedLink>
                                </td>
                            </tr>
                            <% } %>    
                            <logic:equal name="showNewCustomerLink" value="TRUE">
                            <tr>
                                <td class="NArialL" colspan=5>
                                    To add a new customer, please <chiptrack:restrictedLink functionality='<%=Functionality.CUSTOMER_DETAILS%>' action='<%=User.USER_ACTION_VIEW%>' styleClass="leftsection" href='<%=chipTracContext + "/customers.do?action=CreateCustomer"%>' onmouseover="window.status='Click to Add new Customer';return true" onmouseout="window.status='';return true">click here</chiptrack:restrictedLink>
                                </td>
                            </tr>
                            </logic:equal>
                        </table>
                    </td>
                </tr>
                <tr><td><img height=10 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif"></td></tr>
                <tr>
                    <td>
                        <% int bgcount = 0;%>
                        <logic:equal name="showList" value="TRUE">
                        <table border="0" width="100%" bordercolor="#FFFFFF" align=right>
  	                        <tr><td class="NArialL"><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
                            <tr>
                                <td width="15%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Customer Name</font></td>
                                <td width="17%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Action</font></td>
                            </tr>
  	                        <logic:iterate id="Customer" name="customersList" type="com.scalar.chiptrack.sales.Customer">
                            <% bgcount = bgcount + 1; %>
  	                        <tr>
  	                            <td width="15%" align="left" <%if(bgcount%2==0){%> bgcolor='#DEE1E2' <% } else {%> bgcolor='#FFFFEE' <%}%>>
                                      <font class="NArialL">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 	<bean:write name="Customer" property="customerName" /></font>
                                </td>
  	                            <td width="17%" align="center" <%if(bgcount%2==0){%> bgcolor='#DEE1E2' <% } else {%> bgcolor='#FFFFEE' <%}%>>
                                    <font class="NArialL"><chiptrack:linkCustomer page="/salesOrder.do?action=NewSalesOrder"  onmouseover="window.status='Click to Enter New Sales Order';return true" onmouseout="window.status='';return true">New <%=heading%></chiptrack:linkCustomer></font>
  	                            </td>
  	                        </tr>
  	                        </logic:iterate>
                        </table>
                        </logic:equal>
                    </td>
                </tr>
            </table>
            <input type="hidden" name="action" value="">
            <input type="hidden" name="isSample" value="<%=request.getParameter("isSample")%>">
            </html:form>
            <!-- till here -->
            <BR><BR><BR>
        </TD>
        <TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
    </TR>
</TABLE>
<!-- Footer starts here -->
<%@ include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->
</BODY>
</HTML>
